package com.chb.microservice.provider.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.chb.microservice.provider.hystrix.WxMicroHystrixWrapped;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

@RefreshScope
@RestController
@Api(description ="微信模块")
public class WxMicroController {

	@Autowired
	private WxMicroHystrixWrapped wxMicroHystrixWrapped;

	@ApiOperation(value = "登录凭证code获取session_key和openid", httpMethod = "POST", notes = "登录凭证code获取session_key和openid")
	@ApiResponses({ @ApiResponse(code = 400,  message = "请求参数没填好"),
			@ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对") })
	@RequestMapping(value = "/Wx/small_routine", method = RequestMethod.POST)
	public Object findByParatemer(
			@ApiParam(value = "code值", required = true) @RequestParam(value = "code", required = true) String code) {

		return wxMicroHystrixWrapped.findByParatemer(code);
	}

	@ApiOperation(value = "openid获取。。。", httpMethod = "POST", notes = "openid获取。。。")
	@ApiResponses({ @ApiResponse(code = 400, message = "请求参数没填好"),
			@ApiResponse(code = 404, message = "请求路径没有或页面跳转路径不对") })
	@RequestMapping(value = "/Wx/openidGetThing", method = RequestMethod.POST)
	public Object openidGet(
			@ApiParam(value = "类型1,安卓；0,IOS", required = true) @RequestParam(value = "type", required = true) String type, // 1,安卓；0,IOS
			@ApiParam(value = "微信openid", required = true) @RequestParam(value = "backId", required = true) String openId,
			@ApiParam(value = "ucode", required = true) @RequestParam(value = "ucode", required = false) String ucode) {

		return wxMicroHystrixWrapped.openidGet(type, openId, ucode).toString();
	}
	
}
